﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/*
 * ArCamera 统一控制 Btn 点击事件
 */
public class BtnClickController : MonoBehaviour
{
    private void Awake()
    {
        GameObject arSessionOrigin = GameObject.Find("AR Session Origin");

        ((Button)GameObject.Find("Canvas/BtnCheckArCore").GetComponent<Button>()).onClick.AddListener(() => {
            IEnumerator result = CheckArUtils.CheckArSupport();
            ToastUtil.showToast("BtnClickController OnCheckArCoreBtnClick() result.MoveNext() = " + result.MoveNext());
        }); ;

        GameObject objBtnInstallArCoreApk = GameObject.Find("Canvas/BtnInstallArCoreApk");
        ApkManager apkManager = objBtnInstallArCoreApk.AddComponent<ApkManager>();
        ((Button)objBtnInstallArCoreApk.GetComponent<Button>()).onClick.AddListener(() => apkManager.InstallAPK());

        GameObject objBtnTogglePlaneDetectionMode = GameObject.Find("Canvas/BtnTogglePlaneDetectionMode");
        PlaneManager planeManagerTogglePlaneDetectionModel = objBtnTogglePlaneDetectionMode.AddComponent<PlaneManager>();
        ((Button)objBtnTogglePlaneDetectionMode.GetComponent<Button>()).onClick.AddListener(() => planeManagerTogglePlaneDetectionModel.TogglePlaneDetectionMode());

        GameObject objBtnTogglePlaneDetectionEnabled = GameObject.Find("Canvas/BtnTogglePlaneDetectionEnabled");
        PlaneManager planeManagerTogglePlaneDetectionEnabled = objBtnTogglePlaneDetectionEnabled.AddComponent<PlaneManager>();
        ((Button)objBtnTogglePlaneDetectionEnabled.GetComponent<Button>()).onClick.AddListener(() => planeManagerTogglePlaneDetectionEnabled.TogglePlaneDetectionEnabled());

        GameObject objBtnToggleImageTrackingEnabled = GameObject.Find("Canvas/BtnToggleImageTrackingEnabled");
        ImageTrackingManager imageTrackingManager = objBtnToggleImageTrackingEnabled.AddComponent<ImageTrackingManager>();
        ((Button)objBtnToggleImageTrackingEnabled.GetComponent<Button>()).onClick.AddListener(() => imageTrackingManager.ToggleImageTrackingEnabled());

        var planeController = arSessionOrigin.GetComponent<PlaneController>();
        (GameObject.Find("Canvas/BtnPlayVideo").GetComponent<Button>()).onClick.AddListener(() => planeController.OnPlayVideoBtnClick());
        (GameObject.Find("Canvas/BtnPauseVideo").GetComponent<Button>()).onClick.AddListener(() => planeController.OnPauseVideoBtnClick());
        (GameObject.Find("Canvas/BtnStopVideo").GetComponent<Button>()).onClick.AddListener(() => planeController.OnStopVideoBtnClick());
        (GameObject.Find("Canvas/BtnTogglePlaneAddObjType").GetComponent<Button>()).onClick.AddListener(() => planeController.OnBtnTogglePlaneAddObjTypeClick());
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
